package net.maku.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.bean.query.WebTradeRecordQuery;
import net.maku.bean.vo.WebTradeRecordVO;
import net.maku.convert.WebTradeRecordConvert;
import net.maku.entity.WebTradeRecordEntity;
import net.maku.service.WebTradeRecordService;
import net.maku.utils.PageResult;
import net.maku.utils.Result;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 点数使用记录表
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2024-09-02
*/
@RestController
@RequestMapping("maku/web_trade_record")
@Tag(name="点数使用记录表")
@AllArgsConstructor
public class WebTradeRecordController {
    private final WebTradeRecordService webTradeRecordService;

    @GetMapping("page")
    @Operation(summary = "分页")
    //@PreAuthorize("hasAuthority('maku:web_trade_record:page')")
    public Result<PageResult<WebTradeRecordVO>> page(@ParameterObject @Valid WebTradeRecordQuery query){
        PageResult<WebTradeRecordVO> page = webTradeRecordService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    //@PreAuthorize("hasAuthority('maku:web_trade_record:info')")
    public Result<WebTradeRecordVO> get(@PathVariable("id") Long id){
        WebTradeRecordEntity entity = webTradeRecordService.getById(id);

        return Result.ok(WebTradeRecordConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    //@PreAuthorize("hasAuthority('maku:web_trade_record:save')")
    public Result<String> save(@RequestBody WebTradeRecordVO vo){
        webTradeRecordService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    //@PreAuthorize("hasAuthority('maku:web_trade_record:update')")
    public Result<String> update(@RequestBody @Valid WebTradeRecordVO vo){
        webTradeRecordService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    //@PreAuthorize("hasAuthority('maku:web_trade_record:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        webTradeRecordService.delete(idList);

        return Result.ok();
    }
}